# -*- coding: utf-8 -*-
# @Time : 2022-03-24 16:49
# @Author : Z
# @Function :

# int 整形
import json
import os
import random

# Python变量定义是通过赋值来完成的,
# 变量名会指向新的空间，即，变量只会存储最后赋值的数据，这
# 就好比往一个装满水的瓶子注入新的流水，前面装的水会不断的流出，留在瓶子的水一定是最新注入的
a = int(2)
print(type(a))
#  float 浮点型
a = float(2.0)
print(a)
print(type(a))

# str 字符串
a = str("abcdefg")
print("切片a[1:] " + a[1:])
print("切片a[1:2] " + a[1:2])
aa = len(a)
print(aa)
print(type(aa))
print(type(a))
# 复制
b = a
print(b)
# 拼接
print(a + b)
# 查找对应字符的下标，index
print(a.index("a"))
# 切片,要头不要尾
print(a[1:2])
print(a[0:5:1])
# 字符串反转
print("字符串反转后的结果：" + a[::-1])
print("a" in a)
# 移除空格 strip方法去除字符串开头或者结尾的空格
k = "    a  b  cdef  "
print(k.strip())
# 替换replace(old,new,count),不填写count参数，默认替换所有的
print(k.replace(" ", ""))
b = "1234161"
print(b.replace("1", "a", 2))
# 分割split()
a = "1,2,3,4,5,6"
b = a.split(",")
print(type(b))
print(b)

# list 列表

# 字符串转换成列表

name = "abcdef"
listname = list(name)
print(listname)
li = [1, "2", "b", "c"]
print(li)
# 查找，根据索引访问
print(li[1])
# 切片,要头不要尾，0:3,只要0到2的数据，步长为1
print(li[0:3:1])
# 添加
li.append("添加")
ll = ["1", "2", "3"]
# 追加多个值
li.extend(ll)
print(li)
# 修改，通过下标修改
li[0] = "1111"
print(li)
# 删除
li.pop(0)
print(li)
# len 长度
print(len(li))
# 排序 顺序数字>大写>小写
li.sort()
print(li)
# 反转
li.reverse()
print(li)

# 字典
# 通过fromkeys创建字典
ll = ["a", "b", "c"]
# 以ll中的元素作为键
# dict1 =dict.fromkeys(ll)
# print(dict)
# 设置默认值
# dict = dict.fromkeys(ll,"123")
# print(dict)
dic = {"key1": "value1", "key2": "value2", "key3": "value3"}
# print(dic)
# 添加
dic["key4"] = "value4"
print(dic)
# 删除,返回对应的值，并将这个值从字典上移除
a = dic.pop("key4")
print(a)
print(dic)
# 修改
dic["key4"] = "修改后的值"
print(dic)
# 查找,根据key 也就是键来查找值
print(dic.get("key4"))
# 遍历
# print("-------------111111111---------------------------")
# print(dict.keys())
# for key in dic.keys():
#     print(key+":"+dic.get(key))
# for value in dic.values():
#     print(value)
# for item in dic.items():
#     print(item)


# ll = dict(one=1, two=2)
# print(ll)


# 元组
tuple = ("1", "2", "3", "4")
print('元组')
print(tuple[0])
print(type(tuple))
print(tuple)
# 切片
print(tuple[0:2])

ll = ['', '', '点击删除文章', 'click', '//*[text()="{title}"]/../..//*[text()="删除"]', '', '', '', '']
# l.index(''),返回参数所在的索引位置
l = ll[4:]
la = l[:l.index('')]

print(l)
print(la)
print(l.index(''))

aa = ['', '', '点击删除文章', 'click', '//*[text()="{title}"]/../..//*[text()="删除"]', '', '', '', '']
aa = aa[2:]
print(aa)
print(aa.index(''))
aa = aa[:aa.index('')]
print(aa)

# 随机数
ll = random.randint(17, 21)
print(ll)


def test():
    pass


a = b = c = 1
print(id(a))
print(id(b))
print(id(c))

case_report = os.path.join(os.getcwd(), "case")
print(os.getcwd())

a = "0123456"
print(a.index('2'))
print(a.find('2'))

print("-----------------------------------------------------------------------------")
s = "I love you"
ll = s.split(" ")
print(ll)
ll = ll[::-1]
print(ll)
ll = " ".join(ll)
print(ll)
ll = ll[::-1]
print(ll)

s = "I love you"
res = " ".join(s.split(" ")[::-1])[::-1]
print(res)


# eturn [表达式] 结束函数，选择性地返回一个值给调用方，不带表达式的 return 相当于返回 None
# 定义函数
def printme(str):
    # 打印任何传入的字符串
    print(str)
    return


# 调用函数
printme("我要调用用户自定义函数!")
printme("再次调用同一函数")
print(printme("返回值为None"))

print("--------------------------------------")

a = "{}"
b = json.loads(a)
print(b)
print(type(b))



